import {Component, OnInit, ViewChild} from '@angular/core';
import {RatingModalViewComponent} from "../rating-modal-view/rating-modal-view.component";
import {CashierModalViewComponent} from "../cashier-modal-view/cashier-modal-view.component";
import {APARTMENT} from "../../service/apartment.service";
import {CheckStandModel} from "../../model/checkstand.model";
import {LocalStorage} from "../../app.local-storage";
import {ROUTE} from "../../service/route.service";

@Component({
  selector: 'app-my-repair-view',
  templateUrl: './my-repair-view.component.html',
  styleUrls: ['./my-repair-view.component.scss']
})
export class MyRepairViewComponent implements OnInit {
  @ViewChild(RatingModalViewComponent) public ratingModal:any;
  @ViewChild(CashierModalViewComponent) public cashierModal:any;

  constructor(private apartmentApi:APARTMENT,private ls: LocalStorage,private route:ROUTE) { }

  ngOnInit() {
    this.loadMyRepair();
  }
  repairList:any = [];

  loadMyRepair(){
    this.apartmentApi.getMyRepair({},(res:any)=>{
      // 1-待处理，2-待上门，4-待评价，8-已评价
      let list:any = [];
      for(let item of res.content){
        let data:any = {
          id:item.id,
          buzItem:item.buzItem,
          buzProduct:item.buzProduct,
          buzType:item.buzType,
          comment:item.comment,
          commentScore:item.commentScore,
          content:item.content,
          createTime:item.createTime.split(' ',1)[0],
          image:item.image,
          itemName:item.itemName,
          needFee:item.needFee,
          payMoney:item.payMoney,
          payStatus:item.payStatus,
          payTime:item.payTime,
          payType:item.payType,
          productName:item.productName,
          providerId:item.providerId,
          providerName:item.providerName,
          providerPhone:item.providerPhone,
          providerTime:item.providerTime,
          repairFee:item.repairFee,
          status:item.status,
          statusName:item.statusName,
          title:item.title,
          uuid:item.uuid
        }
        list.push(data);
        this.repairList = list;
      }
      console.log(this.repairList);
    })
  }


  statusStyle(item:any){
    let lineHeight = item.status!=3?'100px':'20px';
    let padding = item.status==2||item.status==3?'20px':'0';

  }

  showRatingModalView(item){
    this.ls.set('commentNo',item.uuid);
    this.ratingModal.showModal();
  }
  showCashierModalView(item){
    let checkstand = new CheckStandModel(item.uuid, item.title, item.repairFee, item.id,'personal/myrent')
    this.ls.setObject('checkstand', checkstand);
    this.route.goConfirmPaymentView(item.uuid);
  }

}
